class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

/**
 * @author ghp
 * @title
 * @description
 */
class Solution {
    public int maxProduct(int[] nums) {
        int len = nums.length;
        int max = nums[0];
        int min = nums[0];
        int ans = nums[0];
        for (int i = 1; i < len; ++i) {
            int preMax = max;
            int preMin = min;
            max = Math.max(preMax * nums[i], Math.max(nums[i], preMin * nums[i]));
            min = Math.min(preMin * nums[i], Math.min(nums[i], preMax * nums[i]));
            ans = Math.max(max, max);
        }
        return ans;
    }
}


